home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-0039
/
source
/
dcfileio.mod
< prev
next >
Wrap
Text File
|
1997-04-16
|
36KB
|
1,084 lines
IMPLEMENTATION MODULE DCFileIO;
(*---------------------------------------------------------------------*)
(* File I/O module for DegasConvert *)
(* *)
(* Functions: *)
(* Load & Save Degas Format Pictures *)
(* Load 'TNY' format pictures *)
(* Load 'TN*' format pictures *)
(* *)
(* Save image file. *)
(* *)
(* Amendments: *)
(* 25/ 9/89 LGM : Added conversion of compressed degas and LOGO *)
(* pictures. *)
(* 26/ 8/89 LGM : Add Loading of DOODLE, NEO and then try and load *)
(* anything else as degas format. *)
(* *)
(* Version 2.01 November 1988 L.G. Miller *)
(* Version 2.0 July 1988 L.G. Miller *)
(* Version 1.1 August 1987 L.G.M. *)
(*---------------------------------------------------------------------*)
(*---------------------------------------------------------------------*)
(* Import List *)
(*---------------------------------------------------------------------*)
(* IMPORT Trace; *)
FROM DCGlobal IMPORT DegasPicture, BitPlanesEnum,
LowRes, LowResMaxX, LowResMaxY, LowResNoPlanes,
MedRes, MedResMaxX, MedResMaxY, MedResNoPlanes,
HiRes, HiResMaxX, HiResMaxY, HiResNoPlanes,
BITSPERWORD;
FROM IntLogic IMPORT IOR, IAND;
IMPORT Forms;
FROM SYSTEM IMPORT ADR, ADDRESS, BYTE;
FROM Storage IMPORT ALLOCATE, DEALLOCATE, Available;
FROM Strings IMPORT String, Concat, Length, Assign
Pos, PosLast, Copy, Delete;
IMPORT GemDos;
FROM MyFileSelector IMPORT GetFilename, ParseFilePath;
(*
GetFilename ( VAR DefaultExtension : ARRAY OF CHAR; (* input *)
VAR DefaultPathname : ARRAY OF CHAR; (* i/o *)
VAR SelectedFilename : ARRAY OF CHAR; (* i/o *)
VAR CompleteFilename : ARRAY OF CHAR (* output *)
) : BOOLEAN ;
*)
FROM ManyWindow IMPORT ShowAlert, ShowMouse, HideMouse;
(*-----------------------------------------------------------------------*)
(* Global Constants *)
(*-----------------------------------------------------------------------*)
CONST
CMaxTnyFile = CARDINAL(40000);
CmaxIMGFile = CMaxTnyFile;
CLongZero = LONGCARD(0);
CMaxExtensions = 20;
TYPE
LowResPlaneChar = ARRAY [ BitPlane1 .. BitPlane4 ]
OF ARRAY [ 0 .. 1 ] OF CHAR;
MedResPlaneChar = ARRAY [ BitPlane1 .. BitPlane2 ] OF
ARRAY [ 0 .. 1 ] OF CHAR;
HiResPlaneChar = ARRAY [ 0 .. 1 ] OF CHAR;
PicTypes = ( degas, smalldegas, logo, neo, doodle, tny, unknown );
FileExtStr = ARRAY [ 0 .. 3 ] OF CHAR;
FileType = RECORD
Type : PicTypes;
FileExt : FileExtStr;
END;
FileTypes = ARRAY [ 0 .. CMaxExtensions ] OF FileType;
TnyFileRange = [ 0 .. CMaxTnyFile ];
TnyFile = ARRAY TnyFileRange OF CHAR;
TnyFilePtr = POINTER TO TnyFile;
WordArray = ARRAY [ 0 .. 16000 ] OF BITSET; (* converted tny data *)
WordArrayPtr = POINTER TO WordArray;
CharPtr = POINTER TO CHAR;
(*-----------------------------------------------------------------------*)
(* Global Variables *)
(*-----------------------------------------------------------------------*)
VAR
LastFilename : String; (* store selected pathname for next time *)
KnownFileTypes : FileTypes;
(*-----------------------------------------------------------------------*)
(* Subroutines *)
(*-----------------------------------------------------------------------*)
PROCEDURE NullFill ( VAR s : ARRAY OF CHAR );
VAR i : CARDINAL;
BEGIN
FOR i := 0 TO SHORT(HIGH(s)) DO s[i] := 0C END;
END NullFill;
PROCEDURE ClearPicture( VAR pic : DegasPicture );
VAR line, pg : CARDINAL;
BEGIN
FOR line := 0 TO HiResMaxY DO
FOR pg := 0 TO HIGH(pic.HiResPicture[0]) DO
pic.HiResPicture[line][pg] := BITSET(0H);
END;
END;
END ClearPicture;
(*-----------------------------------------------------------------------*)
(* Initialise known FileTypes array *)
(* *)
(* Note: MUST always be at least ONE Null entry in KnownFileTypesArray. *)
(*-----------------------------------------------------------------------*)
PROCEDURE InitKnownFileTypes;
VAR i : CARDINAL;
BEGIN
FOR i := 0 TO CMaxExtensions DO
NullFill(KnownFileTypes[i].FileExt);
KnownFileTypes[i].Type := unknown;
END;
i := 0;
WITH KnownFileTypes[i] DO Assign('PI1',FileExt); Type:= degas; END; INC(i);
WITH KnownFileTypes[i] DO Assign('PI2',FileExt); Type:= degas; END; INC(i);
WITH KnownFileTypes[i] DO Assign('PI3',FileExt); Type:= degas; END; INC(i);
WITH KnownFileTypes[i] DO Assign('TNY',FileExt); Type:= tny; END; INC(i);
WITH KnownFileTypes[i] DO Assign('TN1',FileExt); Type:= tny; END; INC(i);
WITH KnownFileTypes[i] DO Assign('TN2',FileExt); Type:= tny; END; INC(i);
WITH KnownFileTypes[i] DO Assign('TN3',FileExt); Type:= tny; END; INC(i);
WITH KnownFileTypes[i] DO Assign('TN3',FileExt); Type:= tny; END; INC(i);
WITH KnownFileTypes[i] DO Assign('NEO',FileExt); Type:= neo; END; INC(i);
WITH KnownFileTypes[i] DO Assign('DOO',FileExt); Type:= doodle;END; INC(i);
WITH KnownFileTypes[i] DO Assign('PC1',FileExt); Type:= smalldegas;END; INC(i);
WITH KnownFileTypes[i] DO Assign('PC2',FileExt); Type:= smalldegas;END; INC(i);
WITH KnownFileTypes[i] DO Assign('PC3',FileExt); Type:= smalldegas;END; INC(i);
WITH KnownFileTypes[i] DO Assign('PIC',FileExt); Type:= logo; END; INC(i);
END InitKnownFileTypes;
(*-----------------------------------------------------------------------*)
(* Given a file extension return picture type *)
(*-----------------------------------------------------------------------*)
PROCEDURE QueryPictureType( Ext : ARRAY OF CHAR ) : PicTypes;
VAR i : CARDINAL;
fext : FileExtStr;
BEGIN
i := 0;
Assign(Ext, fext);
WHILE ( KnownFileTypes[i].FileExt <> fext )
AND ( KnownFileTypes[i].FileExt[0] <> 0C ) DO
INC(i);
END;
RETURN KnownFileTypes[i].Type;
END QueryPictureType;
(*----------------------------------------------------------------------*)
(* Try to find and load the file given a name & where to put it *)
(*----------------------------------------------------------------------*)
(* these routines should be able to make it easier to load different
types of files *)
PROCEDURE OpenFile( VAR fnstr : String; VAR filesize : LONGCARD) : INTEGER;
VAR handle : INTEGER;
BEGIN
filesize := 0;
handle := GemDos.Fopen(0, ADR(fnstr));
IF ( handle <= 0 ) THEN RETURN handle END; (* file not found *)
filesize := GemDos.Fseek(2, handle, LONGCARD(0) ) ;
IF GemDos.Fseek(0, handle, LONGCARD(0) ) = 0 THEN END;
RETURN handle;
END OpenFile;
PROCEDURE CloseFile( handle : INTEGER );
BEGIN
IF GemDos.Fclose( handle ) < 0 THEN END;
END CloseFile;
PROCEDURE ReadFile( handle : INTEGER;
destaddr : ADDRESS; size : LONGCARD ) : BOOLEAN;
BEGIN
RETURN ( GemDos.Fread( destaddr, size, handle ) = LONGINT(size) );
END ReadFile;
PROCEDURE SetFilePos( handle : INTEGER; pos : LONGCARD ) : BOOLEAN;
BEGIN
RETURN ( GemDos.Fseek(2, handle, pos ) = pos ) ;
END SetFilePos;
(*---------------------------------------------------------------------*)
(* Load the files... *)
(*---------------------------------------------------------------------*)
PROCEDURE LoadTny ( VAR fnstr : String;
VAR infile : ARRAY OF CHAR ) : BOOLEAN;
VAR
Filelen, duml : LONGCARD;
handle : INTEGER;
reply : BOOLEAN;
BEGIN
handle := OpenFile( fnstr, Filelen );
IF ( handle < 0 ) THEN
RETURN FALSE;
ELSIF ( Filelen < 10 ) THEN
CloseFile( handle );
RETURN FALSE;
END; (* wrong size *)
(* load the file using GemDos block read *)
reply := ReadFile( handle, ADR(infile), Filelen );
CloseFile( handle );
RETURN reply;
END LoadTny;
PROCEDURE LoadDegas ( VAR fnstr : String;
VAR picture : DegasPicture ) : BOOLEAN;
VAR
Filelen, duml : LONGCARD;
handle : INTEGER;
reply : BOOLEAN;
BEGIN
handle := OpenFile( fnstr, Filelen );
IF ( handle < 0 ) THEN
RETURN FALSE;
ELSIF ( Filelen < SIZE(picture) ) THEN
CloseFile( handle );
RETURN FALSE
END; (* wrong size *)
(* load the file using GemDos block read *)
reply := ReadFile( handle, ADR(picture), SIZE(picture) );
CloseFile( handle );
RETURN reply;
END LoadDegas;
PROCEDURE LoadDoodle ( VAR fnstr : String;
VAR picture : DegasPicture ) : BOOLEAN;
VAR
Filelen, duml : LONGCARD;
handle : INTEGER;
reply : BOOLEAN;
BEGIN
handle := OpenFile( fnstr, Filelen );
IF ( handle < 0 ) THEN
RETURN FALSE;
ELSIF ( Filelen <> SIZE(picture.HiResPicture) ) THEN
CloseFile( handle );
RETURN FALSE
END; (* wrong size *)
(* load the file using GemDos block read *)
reply := ReadFile( handle, ADR(picture.HiResPicture), Filelen ) ;
CloseFile( handle );
(* fake up a palette *)
picture.resolution := 2;
picture.HiPalette[0] := 0; (* white *)
RETURN reply;
END LoadDoodle;
PROCEDURE LoadNeo ( VAR fnstr : String;
VAR picture : DegasPicture ) : BOOLEAN;
VAR
Filelen, duml : LONGCARD;
handle : INTEGER;
reply : BOOLEAN;
BEGIN
handle := OpenFile( fnstr, Filelen );
IF ( handle < 0 ) THEN
RETURN FALSE;
ELSIF ( Filelen <= SIZE(picture) ) THEN
CloseFile( handle );
RETURN FALSE;
END; (* wrong size *)
(* load the file using GemDos block read *)
reply := ReadFile( handle, ADR(picture.LowPalette), 128 ) ;
IF NOT reply THEN RETURN reply END;
reply := ReadFile( handle, ADR(picture.HiResPicture),
SIZE(picture.HiResPicture ));
CloseFile( handle );
(* set resolution *)
picture.resolution := 0;
RETURN reply;
END LoadNeo;
PROCEDURE LoadUnknown ( VAR fnstr : String;
VAR picture : DegasPicture ) : BOOLEAN;
VAR
Filelen, duml : LONGCARD;
handle : INTEGER;
reply : BOOLEAN;
BEGIN
handle := OpenFile( fnstr, Filelen );
IF ( handle < 0 ) THEN
RETURN FALSE;
ELSIF ( Filelen <> SIZE(picture) ) THEN
CloseFile( handle );
RETURN FALSE
END; (* wrong size *)
(* load the file using GemDos block read *)
reply := ReadFile( handle, ADR(picture), SIZE(picture) ) ;
CloseFile( handle );
RETURN reply;
END LoadUnknown;
(*-----------------------------------------------------------------------*)
(* Save an area to a File *)
(*-----------------------------------------------------------------------*)
PROCEDURE SaveFile ( VAR fnstr : String;
sourceaddr : ADDRESS;
fsize : LONGCARD ) : BOOLEAN;
VAR BytesWritten : LONGCARD;
Filelen : LONGCARD;
s : String;
button : INTEGER;
handle, dumi : INTEGER;
BEGIN
handle := GemDos.Fopen(0, ADR(fnstr));
IF handle >= 0 THEN
dumi := GemDos.Fclose(handle);
END;
IF handle > 0 THEN
Concat('About to OVERWRITE ',fnstr,s);
button := ShowAlert(s,2,2);
IF button = 2 THEN RETURN FALSE END;
ELSE
handle := GemDos.Fcreate(0, ADR(fnstr));
IF handle < 0 THEN
Concat('Unable to Create... |',fnstr,s);
button := ShowAlert(s,1,1);
RETURN FALSE;
END;
dumi := GemDos.Fclose(handle);
END; (* file not found *)
(* save the file *)
handle := GemDos.Fopen( 2, ADR(fnstr) );
Filelen := GemDos.Fwrite( sourceaddr, fsize, handle );
IF ( GemDos.Fclose( handle ) < 0 ) THEN
Concat('Unable to SAVE... |',fnstr,s);
button := ShowAlert(s,1,1);
RETURN FALSE;
END;
IF ( Filelen < fsize ) THEN
Concat('Unable to SAVE... |',fnstr,s);
button := ShowAlert(s,1,1);
RETURN FALSE;
END;
RETURN TRUE;
END SaveFile;
(*----------------------------------------------------------------------*)
(* Utility Routines for Picture Expansion. *)
(*----------------------------------------------------------------------*)
PROCEDURE InsertChar( res, lineno, pixelgroup : CARDINAL;
plane : BitPlanesEnum;
charno: CARDINAL;
c : CHAR;
VAR pic : DegasPicture);
BEGIN
CASE res OF
LowRes : pic.LowResCharPicture[lineno][pixelgroup][plane][charno]:=c;|
MedRes : pic.MedResCharPicture[lineno][pixelgroup][plane][charno]:=c;|
HiRes : pic.HiResCharPicture[lineno][pixelgroup][charno]:=c;|
END;
END InsertChar;
PROCEDURE InsertWord( res, lineno, pixelgroup : CARDINAL;
plane : BitPlanesEnum;
w : CARDINAL ;
VAR pic : DegasPicture);
BEGIN
CASE res OF
LowRes : pic.LowResPicture[lineno][pixelgroup][plane]:=BITSET(w);|
MedRes : pic.MedResPicture[lineno][pixelgroup][plane]:=BITSET(w);|
HiRes : pic.HiResPicture[lineno][pixelgroup]:=BITSET(w);|
END;
END InsertWord;
PROCEDURE CharToInt( c : CHAR ) : INTEGER;
VAR i : INTEGER;
BEGIN
i := ORD(c);
IF i > 127 THEN
i := i - 256;
END;
RETURN i;
END CharToInt;
PROCEDURE GetNextChar( VAR s : ARRAY OF CHAR;
VAR index : CARDINAL ) : CHAR;
VAR c : CHAR;
BEGIN
c := s[index];
INC(index);
RETURN( c );
END GetNextChar;
PROCEDURE GetNextCard( VAR s : ARRAY OF CHAR; VAR index : CARDINAL; ) : CARDINAL;
VAR c : CARDINAL;
BEGIN
c := ORD(s[index]) * 256;
INC(index);
c := c + ORD(s[index]);
INC(index);
RETURN c;
END GetNextCard;
(*----------------------------------------------------------------------*)
(* Convert LOGO pictures. *)
(*----------------------------------------------------------------------*)
(*----------------------------------------------------------------------*)
(* Format: word Description *)
(* 0 Number of planes *)
(* 1 x-coordinate of picture *)
(* 2 y-coordinate of picture *)
(* 3 width in pixels of picture *)
(* 4 height of picture in pixels *)
(* 5... data *)
(* *)
(* Data: Each scanline is saved sequentially and padded to a *)
(* pixel group boundary ( 16 pixels ). *)
(*----------------------------------------------------------------------*)
PROCEDURE ConvertLOGO( VAR buffer : ARRAY OF CHAR;
VAR degaspic : DegasPicture ) : BOOLEAN;
VAR
NLines : CARDINAL;
inchar (* index into buffer *) : CARDINAL;
command : INTEGER;
curpixelgroup,
curline : CARDINAL;
curplane : BitPlanesEnum;
curcharno : CARDINAL;
curmaxpixelgroup : CARDINAL;
curmaxplane : BitPlanesEnum;
(* Input details *)
xcoord, ycoord,
pixelw, pixelh,
pixelgroupw,
startpixelgroup,
startline : CARDINAL;
card : CARDINAL;
i, : CARDINAL;
pxw : CARDINAL;
mask : CARDINAL;
(* used to remove fringe *)
lastpixelword : CARDINAL;
BEGIN
ClearPicture(degaspic);
curline := 0;
curpixelgroup := 0;
curplane := BitPlane1;
inchar := 0;
card := GetNextCard(buffer, inchar);
xcoord := GetNextCard(buffer, inchar);
ycoord := GetNextCard(buffer, inchar);
pixelw := GetNextCard(buffer, inchar);
pixelh := GetNextCard(buffer, inchar);
pixelgroupw := ( pixelw DIV 16 ) + 1;
CASE card OF
4 : NLines := 200;
curmaxpixelgroup := HIGH(degaspic.LowResPicture[0]);
curmaxplane := BitPlane4;
degaspic.resolution := LowRes;
startline := ( LowResMaxY - pixelh ) DIV 2;
startpixelgroup :=
(( LowResMaxX - pixelw ) DIV 2) DIV BITSPERWORD;
|
2 : NLines := 200;
curmaxpixelgroup := HIGH(degaspic.MedResPicture[0]);
curmaxplane := BitPlane2;
degaspic.resolution := MedRes;
startline := ( MedResMaxY - pixelh ) DIV 2;
startpixelgroup :=
(( MedResMaxX - pixelw ) DIV 2) DIV BITSPERWORD;
|
1 : NLines := 400;
curmaxpixelgroup := HIGH(degaspic.HiResPicture[0]);
curmaxplane := BitPlane1;
degaspic.resolution := HiRes;
startline := ( HiResMaxY - pixelh ) DIV 2;
startpixelgroup :=
(( HiResMaxX - pixelw ) DIV 2) DIV BITSPERWORD;
|
ELSE
RETURN FALSE;
END;
FOR i := 0 TO 15 DO (* mono palette *)
degaspic.LowPalette[i] := 0H;
END;
degaspic.LowPalette[0] := 0777H
(* set mask for fringe in final 16 bit pixels *)
mask := 0FFFFH;
card := 1;
FOR i := 0 TO ( pixelw MOD BITSPERWORD ) DO
mask := mask - card;
card := card * 2;
END;
lastpixelword := startpixelgroup + pixelgroupw - 1;
FOR curline := startline TO startline + pixelh - 1 DO
FOR curpixelgroup := startpixelgroup TO lastpixelword DO
FOR curplane := BitPlane1 TO curmaxplane DO
card := GetNextCard(buffer, inchar);
IF curpixelgroup = lastpixelword THEN
card := IAND(card,mask);
END;
InsertWord( degaspic.resolution,
curline, curpixelgroup, curplane,
card,
degaspic);
END;
END;
END;
RETURN TRUE;
END ConvertLOGO;
(*----------------------------------------------------------------------*)
(* Convert Compressed DEGAS *)
(*----------------------------------------------------------------------*)
PROCEDURE ConvertPC( VAR buffer : ARRAY OF CHAR;
VAR degaspic : DegasPicture ) : BOOLEAN;
VAR
NLines : CARDINAL;
inchar (* index into buffer *) : CARDINAL;
command : INTEGER;
curpixelgroup,
curline : CARDINAL;
curplane : BitPlanesEnum;
curcharno : CARDINAL;
curmaxpixelgroup : CARDINAL;
curmaxplane : BitPlanesEnum;
ch : CHAR;
card : CARDINAL;
i : CARDINAL;
nchars : CARDINAL;
PROCEDURE NextPlane;
BEGIN
IF curplane = curmaxplane THEN
curplane := BitPlane1;
ELSE
INC(curplane);
END;
END NextPlane;
PROCEDURE NextPixelGroup;
BEGIN
INC(curpixelgroup);
IF curpixelgroup > curmaxpixelgroup THEN
IF curplane = curmaxplane THEN
INC(curline);
curplane := BitPlane1;
ELSE
NextPlane;
END;
curpixelgroup := 0;
END;
END NextPixelGroup;
PROCEDURE NextCharno;
BEGIN
IF curcharno = 0 THEN
INC(curcharno);
ELSE
curcharno := 0;
NextPixelGroup;
END;
END NextCharno;
(* continue filling picture by repeating character, nchars times *)
PROCEDURE ScanLineRepeat( nchars : CARDINAL; ch : CHAR );
BEGIN
WHILE nchars > 0 DO
InsertChar( degaspic.resolution,
curline, curpixelgroup, curplane, curcharno,
ch,
degaspic);
NextCharno;
DEC(nchars);
END;
END ScanLineRepeat;
(* continue filling picture with nchars from the input *)
PROCEDURE ScanLineCopy( nchars : CARDINAL; );
VAR ch : CHAR;
BEGIN
WHILE nchars > 0 DO
ch := GetNextChar(buffer, inchar);
InsertChar( degaspic.resolution,
curline, curpixelgroup, curplane, curcharno,
ch,
degaspic);
NextCharno;
DEC(nchars);
END;
END ScanLineCopy;
BEGIN
curline := 0;
curpixelgroup := 0;
curcharno := 0;
curplane := BitPlane1;
inchar := 0;
card := GetNextCard(buffer, inchar);
card := IAND( card, INTEGER(08003H));
CASE card OF
08000H : NLines := 200;
curmaxpixelgroup := HIGH(degaspic.LowResPicture[0]);
curmaxplane := BitPlane4;
degaspic.resolution := LowRes; |
08001H : NLines := 200;
curmaxpixelgroup := HIGH(degaspic.MedResPicture[0]);
curmaxplane := BitPlane2;
degaspic.resolution := MedRes; |
08002H : NLines := 400;
curmaxpixelgroup := HIGH(degaspic.HiResPicture[0]);
curmaxplane := BitPlane1;
degaspic.resolution := HiRes; |
ELSE
RETURN FALSE;
END;
FOR i := 0 TO 15 DO
degaspic.LowPalette[i] := GetNextCard(buffer, inchar);
END;
LOOP
IF curline >= NLines THEN EXIT; END;
command := CharToInt(GetNextChar(buffer, inchar));
IF command > 0 THEN
ScanLineCopy( command+1 );
ELSIF command > -127 THEN
nchars := ABS(command) + 1;
ch := GetNextChar(buffer, inchar);
ScanLineRepeat( nchars, ch);
END;
END;
RETURN TRUE;
END ConvertPC;
(*----------------------------------------------------------------------*)
(* Convert Tiny picture to Degas *)
(*----------------------------------------------------------------------*)
(*----------------------------------------------------------------------*)
(* The documentation issued with the 'Tinypic' program explaining the *)
(* layout of the compressed file is incorrect in one or two details. *)
(* The layout for the compressed file is:- *)
(* *)
(* Size ( bytes ) description *)
(* 1 picture resolution ( +3 if rotation info ) *)
(* 4 rotation info if res >= 3 *)
(* 32 palette *)
(* 2 count of control BYTES *)
(* 2 count of data WORDS *)
(* n control bytes *)
(* n data words *)
(* *)
(* The compressed data was produced by scanning the data in a degas *)
(* picture as follows: *)
(* *)
(* 1) Each colour plane is processed in turn, i.e. all plane 1 *)
(* is processed before plane 2. *)
(* *)
(* 2) Each plane is processed in vertical columns of words. *)
(* *)
(*----------------------------------------------------------------------*)
PROCEDURE ConvertTny( VAR buffer : ARRAY OF CHAR;
VAR degaspic : DegasPicture ) : BOOLEAN;
VAR
NLines : CARDINAL;
incomchar (* index into buffer *),
indatachar : CARDINAL;
command : INTEGER;
curpixelgroup,
curline : CARDINAL;
curplane : BitPlanesEnum;
curmaxpixelgroup : CARDINAL;
curmaxplane : BitPlanesEnum;
incomcount,
indatacount : CARDINAL;
picres : CARDINAL;
ch : CHAR;
card : CARDINAL;
i : CARDINAL;
nchars : CARDINAL;
PROCEDURE NextPlane; (* slowest *)
BEGIN
IF curplane = curmaxplane THEN
curplane := BitPlane1;
ELSE
INC(curplane);
END;
END NextPlane;
PROCEDURE NextPixelGroup; (* next fastest *)
BEGIN
INC(curpixelgroup);
IF curpixelgroup > curmaxpixelgroup THEN
IF curplane = curmaxplane THEN
RETURN;
ELSE
NextPlane;
curpixelgroup := 0;
END;
END;
END NextPixelGroup;
PROCEDURE NextLine; (* changes fastest *)
BEGIN
INC(curline);
IF curline >= NLines THEN
NextPixelGroup;
curline := 0;
END;
END NextLine;
PROCEDURE ScanLineRepeat( nchars : CARDINAL; word : CARDINAL );
BEGIN
WHILE nchars > 0 DO
InsertWord( degaspic.resolution,
curline, curpixelgroup, curplane,
word,
degaspic);
NextLine;
DEC(nchars);
END;
END ScanLineRepeat;
PROCEDURE ScanLineCopy( nchars : CARDINAL; );
VAR word : CARDINAL;
BEGIN
WHILE nchars > 0 DO
word := GetNextCard(buffer, indatachar);
InsertWord( degaspic.resolution,
curline, curpixelgroup, curplane,
word,
degaspic);
NextLine;
DEC(nchars);
END;
END ScanLineCopy;
BEGIN
curline := 0;
curpixelgroup := 0;
curplane := BitPlane1;
incomchar := 0;
indatachar := 0;
picres := CharToInt(GetNextChar(buffer, incomchar));
IF picres >= 3 THEN (* has rotation info - 4 bytes *)
DEC(picres, 3);
FOR i := 0 TO 3 DO
ch := GetNextChar(buffer,incomchar);
END; (* for *)
END;
degaspic.resolution := LowRes; (* patch *)
CASE degaspic.resolution OF
LowRes, MedRes, HiRes
: NLines := 200;
curmaxpixelgroup := HIGH(degaspic.LowResPicture[0]);
curmaxplane := BitPlane4; |
END;
FOR i := 0 TO 15 DO
degaspic.LowPalette[i] := GetNextCard(buffer, incomchar);
END;
incomcount := GetNextCard(buffer, incomchar);
indatacount := GetNextCard(buffer, incomchar);
indatachar := incomchar + incomcount;
LOOP
IF incomcount = 0 THEN EXIT; END;
command := CharToInt(GetNextChar(buffer, incomchar));
DEC(incomcount);
IF command < 0 THEN
nchars := ABS(command);
ScanLineCopy( nchars );
ELSIF command = 1 THEN
nchars := GetNextCard(buffer, incomchar);
DEC(incomcount,2);
ScanLineCopy( nchars );
ELSIF command > 1 THEN
nchars := ABS(command);
ScanLineRepeat( nchars, GetNextCard(buffer, indatachar) );
ELSIF command = 0 THEN
nchars := GetNextCard(buffer, incomchar);
DEC(incomcount,2);
ScanLineRepeat( nchars, GetNextCard(buffer, indatachar) );
END;
END;
degaspic.resolution := picres;
RETURN TRUE;
END ConvertTny;
(*----------------------------------------------------------------------*)
(* Library Routines *)
(*----------------------------------------------------------------------*)
PROCEDURE LoadDegasFile( VAR picture : DegasPicture ;
VAR fname : String ) : BOOLEAN;
VAR
FileExt : FileExtStr;
cpathname, pdrive, pfpath, pfname : String;
fileloaded : BOOLEAN;
filelen : LONGCARD;
InTnyFile : TnyFilePtr;
BEGIN
NullFill(pfpath);
NullFill(cpathname);
ShowMouse;
fileloaded := GetFilename('*',
pfpath,
LastFilename,
cpathname);
HideMouse;
IF NOT fileloaded THEN
RETURN fileloaded;
END; (* cancel or empty filename *)
ParseFilePath( cpathname, pdrive, pfpath, pfname, FileExt );
CASE QueryPictureType( FileExt ) OF
tny : IF NOT Available(CMaxTnyFile) THEN
IF ShowAlert('NO Room for TNY buffer',1,1) = 0 THEN END;
RETURN FALSE;
END;
ALLOCATE(InTnyFile, CMaxTnyFile);
IF InTnyFile = NIL THEN
IF ShowAlert('NO Room for InTnyFile',1,1) = 0 THEN END;
END;
fileloaded := LoadTny(cpathname, InTnyFile^ );
IF fileloaded THEN
fileloaded := ConvertTny( InTnyFile^, picture );
END; (* if *)
DEALLOCATE(InTnyFile, CMaxTnyFile); |
smalldegas
: IF NOT Available(CMaxTnyFile) THEN
IF ShowAlert('NO Room for PC buffer',1,1) = 0 THEN END;
RETURN FALSE;
END;
ALLOCATE(InTnyFile, CMaxTnyFile);
IF InTnyFile = NIL THEN
IF ShowAlert('NO Room for PC',1,1) = 0 THEN END;
END;
fileloaded := LoadTny(cpathname, InTnyFile^ );
IF fileloaded THEN
fileloaded := ConvertPC( InTnyFile^, picture );
END; (* if *)
DEALLOCATE(InTnyFile, CMaxTnyFile); |
logo
: IF NOT Available(CMaxTnyFile) THEN
IF ShowAlert('NO Room for logo buffer',1,1) = 0 THEN END;
RETURN FALSE;
END;
ALLOCATE(InTnyFile, CMaxTnyFile);
IF InTnyFile = NIL THEN
IF ShowAlert('NO Room for logo',1,1) = 0 THEN END;
END;
fileloaded := LoadTny(cpathname, InTnyFile^ );
IF fileloaded THEN
fileloaded := ConvertLOGO( InTnyFile^, picture );
END; (* if *)
DEALLOCATE(InTnyFile, CMaxTnyFile); |
degas : fileloaded := LoadDegas(cpathname, picture); |
neo : fileloaded := LoadNeo( cpathname, picture ); |
doodle : fileloaded := LoadDoodle( cpathname, picture );
ELSE
fileloaded := LoadUnknown( cpathname, picture ) ;
END;
fname := cpathname;
RETURN fileloaded;
END LoadDegasFile;
PROCEDURE SaveDegasFile( VAR picture : DegasPicture ) : BOOLEAN ;
CONST
Defext = 'PI3';
VAR
sfn, pname, cpathname : String;
filesaved : BOOLEAN;
button, i : INTEGER;
BEGIN
NullFill(pname);
NullFill(sfn);
NullFill(cpathname);
Assign(LastFilename, sfn);
IF sfn[0] # 0C THEN
i := 13;
WHILE ( i > 1 ) & ( sfn[i] = 0C ) DO DEC(i) END;
IF sfn[i] # '3' THEN
sfn[i] := '3';
sfn[i-1] := 'I';
sfn[i-2] := 'P';
END;
END;
ShowMouse;
filesaved :=GetFilename(Defext, pname, sfn, cpathname);
IF NOT filesaved THEN
RETURN FALSE
END; (* cancel or empty filename *)
(* check the extension *)
i := 0;
WHILE ( i < 65 ) & ( cpathname[i] > 0C ) DO INC(i) END;
IF i < 4 THEN RETURN FALSE END; (* damn strange file name *)
DEC(i);
IF ( cpathname[i-3] = '.' ) THEN
i := i - 4; (* last char of name *)
END;
(* assume no extension added.. must write a decent validation routine *)
INC(i);
cpathname[i] := 0C;
Concat(cpathname,'.PI3',cpathname);
filesaved := SaveFile(cpathname, ADR(picture), SIZE(picture));
RETURN filesaved;
END SaveDegasFile;
(*----------------------------------------------------------------------*)
(* Save the '.IMG' File. *)
(*----------------------------------------------------------------------*)
PROCEDURE SaveImageFile( IMGLen : CARDINAL;
IMGFilePtr : ADDRESS ) : BOOLEAN;
VAR
FileExt : FileExtStr;
cpathname, pdrive, pfpath, pfname : String;
sfn : String;
filesaved : BOOLEAN;
button, i : INTEGER;
BEGIN
NullFill(pfpath);
NullFill(sfn);
NullFill(cpathname);
Assign(LastFilename,sfn);
IF sfn[0] # 0C THEN
i := 13;
WHILE ( i > 1 ) & ( sfn[i] = 0C ) DO DEC(i) END;
IF sfn[i] # 'G' THEN
sfn[i-2] := 'I';
sfn[i-1] := 'M';
sfn[i] := 'G';
END;
END;
ShowMouse;
filesaved :=GetFilename('IMG', pfpath, sfn, cpathname);
IF NOT filesaved THEN
RETURN FALSE
END; (* cancel or empty filename *)
(* check the extension *)
ParseFilePath( cpathname, pdrive, pfpath, pfname, FileExt );
NullFill(cpathname);
Assign(pdrive,cpathname);
Concat(cpathname,':',cpathname);
Concat(cpathname, pfpath ,cpathname);
Concat(cpathname, pfname ,cpathname);
(* assume no extension added.. must write a decent validation routine *)
Concat(cpathname,'.IMG',cpathname);
filesaved := SaveFile(cpathname, IMGFilePtr, LONG(IMGLen));
RETURN filesaved;
END SaveImageFile;
BEGIN
LastFilename := 0C;
InitKnownFileTypes;
END DCFileIO.